package com.br.android.widingwheels.adapter;

import java.text.DecimalFormat;
import java.util.Currency;
import java.util.List;
import java.util.Locale;

import com.br.android.widingwheels.R;
import com.br.android.widingwheels.entidades.Gasto;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ListaGastosAdapter extends BaseAdapter {

	private List<Gasto> listGastos;
	private Context context;
	
	public ListaGastosAdapter(Context context, List<Gasto> listGastos){
		this.context = context;
		this.listGastos = listGastos;
	}

	@Override
	public int getCount() {
		return listGastos.size();
	}

	@Override
	public Object getItem(int position) {
		return listGastos.get(position);
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View viewParam, ViewGroup viewGroup) {
		Gasto gasto = listGastos.get(position);
		
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(R.layout.layout_adapter_lista_gasto, null);
		
		TextView viewGasto = (TextView) view.findViewById(R.id.textViewAdapterGasto);
		TextView viewCategoria = (TextView) view.findViewById(R.id.textViewAdapterCategoria);
		TextView viewData = (TextView) view.findViewById(R.id.textViewAdapterData);
		TextView viewValor = (TextView) view.findViewById(R.id.textViewAdapterValor);
		
		Currency currency = Currency.getInstance(Locale.getDefault());
		DecimalFormat format = new DecimalFormat(currency.getSymbol() + " ###,###,##0.00");
		
		viewGasto.setText(gasto.getNomeGasto());
		viewCategoria.setText(gasto.getCategoriaGasto());
		viewData.setText(gasto.getDataGasto());
		viewValor.setText(format.format(gasto.getValorGasto()));
		
		return view;
	}
	
	
	
}
